home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / gempp19.zoo / gem++19 / src / gema.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-20  |  5.9 KB  |  317 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1992,1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11.  
  12. #include <vt52.h>
  13.  
  14. #include <aesbind.h>
  15. #include "gema.h"
  16. #include "gemw.h"
  17. #include "gemm.h"
  18. #include "gemt.h"
  19. #include "gemda.h"
  20. #include "geme.h"
  21. #include "gemks.h"
  22. #include "grect.h"
  23. #include "contract.h"
  24. #include "scancode.h"
  25.  
  26. #ifndef WM_BOTTOMED
  27. #define WM_BOTTOMED 33
  28. #endif
  29.  
  30. GEMactivity::WL::WL(GEMwindow *Wind, GEMactivity::WL *n) :
  31.     Window(Wind),
  32.     Next(n),
  33.     Prev(n ? n->Prev : 0)
  34. {
  35.     if (n) n->Prev=this;
  36. }
  37.  
  38. GEMactivity::GEMactivity() :
  39.     W(0), Menu(0), Acc(0), Timer(0), KeySink(0)
  40. { }
  41.  
  42. GEMactivity::~GEMactivity()
  43. { }
  44.  
  45. // XXX This is a bit of a problem.
  46. // XXX Maybe the desktop shouldn't be a window.
  47. //
  48. static bool IsDesktop(GEMwindow* w)
  49. {
  50.     return w->IsOpen() && w->Handle()==0;
  51. }
  52.  
  53. void GEMactivity::AddWindow(GEMwindow& w)
  54. {
  55.     W=new struct WL(&w,W);
  56. }
  57.  
  58. void GEMactivity::RemoveWindow(GEMwindow& w)
  59. {
  60.     for (WL* c=W; c && c->Window!=&w;  c=c->Next)
  61.         ;
  62.  
  63.     if (c) {
  64.         // Cut it out
  65.         if (c->Prev) c->Prev->Next=c->Next;
  66.         if (c->Next) c->Next->Prev=c->Prev;
  67.         if (c==W) W=c->Next;
  68.  
  69.         delete c;
  70.     }
  71. }
  72.  
  73. void GEMactivity::SetMenu(GEMmenu* m)
  74. {
  75.     Menu=m;
  76. }
  77.  
  78. void GEMactivity::SetTimer(GEMtimer* t)
  79. {
  80.     Timer=t;
  81. }
  82.  
  83. void GEMactivity::SetKeySink(GEMkeysink* k)
  84. {
  85.     KeySink=k;
  86. }
  87.  
  88. void GEMactivity::SetDeskAccessory(GEMdeskaccessory* a)
  89. {
  90.     Acc=a;
  91. }
  92.  
  93. void GEMactivity::Do()
  94. {
  95.     GEMfeedback res=ContinueInteraction;
  96.  
  97.     BeginDo();
  98.  
  99.     while (res != EndInteraction) {
  100.         res=OneDo();
  101.     }
  102.  
  103.     EndDo();
  104. }
  105.  
  106. void GEMactivity::BeginDo()
  107. {
  108.     if (Menu) Menu->Show();
  109.  
  110.     graf_mouse(ARROW,0);
  111. }
  112.  
  113. GEMfeedback GEMactivity::OneDo()
  114. {
  115.     return OneDo(0xffff); // Allow any events
  116. }
  117.  
  118. GEMfeedback GEMactivity::OneDo(int eventmask)
  119. {
  120.     GEMfeedback res=ContinueInteraction;
  121.  
  122.     GEMevent event;
  123.  
  124.     int get=MU_BUTTON|MU_MESAG;
  125.  
  126.     if (Timer && Timer->NextInterval()>=0) {
  127.         get|=MU_TIMER;
  128.         event.Interval(Timer->NextInterval());
  129.     }
  130.  
  131.     if (KeySink) get|=MU_KEYBD;
  132.  
  133.     event.Get(get&eventmask);
  134.  
  135.     if (event.Keyboard()) {
  136.         res=KeySink->Consume(event);
  137.     }
  138.  
  139.     if (event.Timer()) {
  140.         res=Timer->ExpireNext(event);
  141.     }
  142.  
  143.     if (event.Button()) {
  144.         GEMwindow *win=0;
  145.         for (WL* c=W; c && !win; c=c->Next) {
  146.             int X,Y,W,H;
  147.             if (c->Window->IsOpen()) {
  148.                 wind_get(c->Window->Handle(),WF_WORKXYWH,&X,&Y,&W,&H);
  149.                 if (event.X()>=X && event.X()<X+W && event.Y()>=Y && event.Y()<Y+H)
  150.                     win=c->Window;
  151.             }
  152.         }
  153.         if (win) res=win->Click(event);
  154.     }
  155.  
  156.     if (event.Message()) {
  157.         res = PerformMessage(event);
  158.     }
  159.  
  160.     return res;
  161. }
  162.  
  163. void GEMactivity::EndDo()
  164. {
  165.     if (Menu) Menu->Hide();
  166. }
  167.  
  168. GEMwindow* GEMactivity::Window(int ID) const
  169. {
  170.     for (WL* c=W; c && c->Window->Handle()!=ID;  c=c->Next)
  171.         ;
  172.     return c ? c->Window : 0;
  173. }
  174.  
  175. GEMactivity::WL* GEMactivity::ListWindow(int ID) const
  176. {
  177.     for (WL* c=W; c && c->Window->Handle()!=ID;  c=c->Next)
  178.         ;
  179.     return c;
  180. }
  181.  
  182. void GEMactivity::Bottomed(const GEMwindow& w)
  183. {
  184.     // Find the window.
  185.     for (WL* c=W; c && c->Window!=&w;  c=c->Next)
  186.         ;
  187.  
  188.     if (c) {
  189.         // Find the end (&& Can't bottom below desktop root window)
  190.         WL* end=c;
  191.         while (end->Next && !IsDesktop(end->Next->Window)) {
  192.             end=end->Next;
  193.         }
  194.  
  195.         // If found and not already last.
  196.         if (c!=end) {
  197.             // Cut c out
  198.             if (c->Prev) c->Prev->Next=c->Next;
  199.             if (c->Next) c->Next->Prev=c->Prev;
  200.             if (c==W) W=c->Next;
  201.  
  202.             // Put c at end
  203.             c->Next=end->Next;
  204.             if (c->Next) c->Next->Prev=c;
  205.             end->Next=c;
  206.             c->Prev=end;
  207.         }
  208.     }
  209. }
  210.  
  211. void GEMactivity::Topped(const GEMwindow& w)
  212. {
  213.     // Find the window.
  214.     for (WL* c=W; c && c->Window!=&w;  c=c->Next)
  215.         ;
  216.  
  217.     // If found and not already first.
  218.     if (c && c!=W) {
  219.         // Cut it out.
  220.         if (c->Prev) c->Prev->Next=c->Next;
  221.         if (c->Next) c->Next->Prev=c->Prev;
  222.  
  223.         // Put at head.
  224.         c->Next=W;
  225.         c->Prev=0;
  226.         W->Prev=c;
  227.         W=c;
  228.     }
  229. }
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. GEMfeedback GEMactivity::PerformMessage(const GEMevent& event)
  237. {
  238.     GEMfeedback    r = ContinueInteraction;
  239.  
  240.     if (event.Message(0)==MN_SELECTED && Menu) {
  241.         return Menu->Select(event);
  242.     } else if (event.Message(0)==AC_OPEN) {
  243.         if (Acc) Acc->Open(event);
  244.         return ContinueInteraction;
  245.     } else if (event.Message(0)==AC_CLOSE) {
  246.         if (Acc) Acc->Close(event);
  247.         return ContinueInteraction;
  248.     }
  249.  
  250.     GEMwindow* To=Window(event.Message(3));
  251.  
  252.     if (To) {
  253.         switch (event.Message(0)) {
  254.          case WM_NEWTOP:        // it's a test
  255.             form_alert(1,"[1][ NewTop Message received! ][  OK  ]");
  256.  
  257.         break; case WM_REDRAW:
  258.             To->RedrawOverlaps(GRect(event.Message(4),event.Message(5),event.Message(6),event.Message(7)));
  259.  
  260.         break; case WM_CLOSED:    r=To->UserClosed();
  261.         break; case WM_MOVED:    To->UserMoved(event.Message(4),event.Message(5));
  262.         break; case WM_TOPPED:    To->Top(event);
  263.         break; case WM_BOTTOMED:    To->Bottom(event);
  264.         break; case WM_FULLED:    To->UserFulled();
  265.         break; case WM_SIZED:    To->UserResized(event.Message(6),event.Message(7));
  266.         break; case WM_VSLID:    To->VSlidered(event.Message(4));
  267.         break; case WM_HSLID:    To->HSlidered(event.Message(4));
  268.  
  269.         break; case WM_ARROWED:
  270.             switch (event.Message(4)) {
  271.              case WA_UPLINE:
  272.                 To->LineUp();
  273.             break; case WA_DNLINE:
  274.                 To->LineDown();
  275.             break; case WA_UPPAGE:
  276.                 To->PageUp();
  277.             break; case WA_DNPAGE:
  278.                 To->PageDown();
  279.             break; case WA_LFLINE:
  280.                 To->ColumnLeft();
  281.             break; case WA_RTLINE:
  282.                 To->ColumnRight();
  283.             break; case WA_LFPAGE:
  284.                 To->PageLeft();
  285.             break; case WA_RTPAGE:
  286.                 To->PageRight();
  287.             }
  288.         }
  289.     }
  290.     
  291.     if (r == RedrawMe) {
  292.         To->RedrawOverlaps(To->WorkRect());
  293.         r = ContinueInteraction;
  294.     }
  295.  
  296.     return r;
  297. }
  298.  
  299. void GEMactivity::Dump()
  300. {
  301.     printf("\n");
  302.     WL* w=W;
  303.  
  304.     if (w->Prev!=0) {
  305.         printf("window list head error!\n");
  306.     }
  307.  
  308.     while (w) {
  309.         GEMwindow* gw=w->Window;
  310.         printf("window %x %s %d %s\n",gw,gw->Name(),gw->Handle(),gw->IsOpen() ? "open" : "closed");
  311.         if (w->Next && w->Next->Prev!=w) {
  312.             printf("window list error!\n");
  313.         }
  314.         w=w->Next;
  315.     }
  316. }
  317.